/*
 *  AAttrList.h
 *  
 *
 *  Created by Peter on 23.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef A_ATTR_LIST_H
#define A_ATTR_LIST_H

#include "AObject.h"

#include <map>

/*
 * An attribute list is basically a set of key-value pairs. The key is always a
 * string, the values can be different and mixed types.
 * Avid apparently uses these things quite excessively thougout Media Composer.
 *
 * Version is 1 (MC 5.5)
 */
class AAttrList : public AObject
{
	
public:
	
	A_DECLARE_CLASS( 'ATTR', AAttrList, AObject );
	
	enum AttrType
	{
		kOMFNullAttribute    = 0,
		kOMFIntegerAttribute = 1,	
		kOMFStringAttribute  = 2,
		kOMFObjectAttribute  = 3,
		kOMFBobAttribute     = 4
	};
	
	struct AttrItem
	{
		AttrType _type;
		AttrItem( AttrType type ) : _type( type ) {}
		virtual ~AttrItem(){}
	};
	
	struct NullAttrItem : public AttrItem {
		NullAttrItem() : AttrItem( kOMFNullAttribute ){}
	};
	
	struct IntAttrItem : public AttrItem {
		IntAttrItem( int value ) : AttrItem( kOMFIntegerAttribute ), _value( value ){}
		int _value;
	};
	
	struct StringAttrItem : public AttrItem {
		StringAttrItem( const std::string& value ) : AttrItem( kOMFStringAttribute ), _value( value ){}
		std::string _value;
	};
	
	struct ObjectAttrItem : public AttrItem {
		ObjectAttrItem( AObject* value ) : AttrItem( kOMFObjectAttribute ), _value( value ){}
		AObject* _value;
	};
	
	class BobAttrItem; // TODO
	
	std::string getAttrAsString( const std::string& attrName ) const;
	std::string getAttrAsString( const AttrItem& attr ) const;
	
	// AObject serialization overrides
	virtual void readFromStream( AStream& str, const AObjDoc& objd );
	virtual void writeToStream( AStream& str ) const;
	
	virtual void dump( std::ostream& str ) const;
	
protected:
	
	typedef std::map< std::string, AttrItem* > AttrMap;
	
	AAttrList::AttrItem* findItem( const std::string& attrName ) const;
	
	AttrMap _items;
	
};

#endif /*Inclusion Guard*/